package com.aznest.controller;

import com.aznest.entity.*;
import com.aznest.result.Result;
import com.aznest.service.HotelService;
import com.aznest.vo.HotelVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 酒店前端操作接口
 **/
@RestController
@RequestMapping("/hotel")
@Api(tags = "酒店相关接口")
@Slf4j
public class HotelController {

    @Resource
    private HotelService hotelService;


    /**
     * 添加酒店
     */
    @PostMapping("/add")
    @ApiOperation("添加酒店")
    public Result add(@RequestBody Hotel hotel) {

        hotelService.add(hotel);
        return Result.success();
    }


    /**
     * 更新酒店
     * @param hotel
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("更新酒店")
    public Result update(@RequestBody Hotel hotel) {
        hotelService.update(hotel);
        return Result.success();
    }

    /**
     * 根据ID删除酒店
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据ID删除酒店")
    public Result delete(@PathVariable Integer id) {
        hotelService.deleteById(id);
        return Result.success();
    }

    /**
     * 批量删除酒店
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/batch")
    @ApiOperation("批量删除酒店")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        hotelService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 根据ID查询酒店
     * @param id
     * @return
     */
    @GetMapping("/selectById/{id}")
    @ApiOperation("根据ID查询酒店")
    public Result selectById(@PathVariable Integer id) {
        Hotel hotel = hotelService.selectById(id);
        return Result.success(hotel);
    }

    /**
     * 根据酒店名称查询
     * @param name
     * @return
     */
    @GetMapping("/selectByName")
    @ApiOperation("根据酒店名称查询")
    public Result selectByName(@RequestParam String name) {
        List<HotelVO> list = hotelService.selectByName(name);
//        List<Hotel> list = hotelService.selectByName(name);
        return Result.success(list);
    }

    /**
     * 查询所有酒店
     * @param hotel
     * @return
     */
    @GetMapping("/selectAll")
    @ApiOperation("查询所有酒店")
    public Result selectAll(Hotel hotel) {
        List<HotelVO> list = hotelService.selectAll(hotel);
        return Result.success(list);
    }

    /**
     * 条件查询酒店信息
     * @return
     */
    @GetMapping("/selectAllOK")
    @ApiOperation("条件查询酒店信息")
    public Result selectAllOK() {
        List<Hotel> list = hotelService.selectAllOK();
        return Result.success(list);
    }

    /**
     * 分页查询酒店信息
     */
    @GetMapping("/selectPage")
    @ApiOperation("分页查询酒店信息")
    public Result selectPage(Hotel hotel,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Hotel> page = hotelService.selectPage(hotel, pageNum, pageSize);
        return Result.success(page);
    }
    /**
     * 基于协同过滤算法推荐用户酒店
     * @return
     */
    @GetMapping("/recommend")
    @ApiOperation("基于协同过滤算法推荐酒店")
    public Result recommend(){
        List<HotelVO> hotelVOList = hotelService.recommend();
        return Result.success(hotelVOList);
    }

    /**
     * 查询热点酒店
     * @return
     */
    @GetMapping("/selectHot")
    @ApiOperation("热门酒店")
    public Result selectHot(){
        List<HotelVO> hotelVOList = hotelService.selectHot();
        return Result.success(hotelVOList);
    }

}
